# ---------- constants ---------- #
import json
import time
import logging.config
import pygame

# ---------- logging ---------- #
# 日志配置字典
with open("lib/logs/config/config.json", "r") as f:
    LOGGING_DIC = json.loads(f.read())
LOGGING_DIC["handlers"]["file_info_handler"]["filename"] = f"lib/logs/Snake/{time.strftime('%m-%d')}.log"

logging.config.dictConfig(LOGGING_DIC)
logger1 = logging.getLogger('Snake')
logger2 = logging.StreamHandler()
logger1.addHandler(logger2)

with open("core/modules/static.json", "r") as f:
    openSnake_Dict = json.loads(f.read())
    if openSnake_Dict["pot"] == "True":
        openSnake_Dict["pot"] = True
    else:
        openSnake_Dict["pot"] = False


def info(data):
    logger1.info(data)
    logger2.setLevel(logging.DEBUG)


SCREENSIZE = (800, 600)
SCREENRECT = pygame.Rect(0, 0, SCREENSIZE[0], SCREENSIZE[1])
CAPTION = 'MiniSnake'
FPS = 40

START_TILE = (20, 20)
START_SEGMENTS = 7

MOVE_RATE = 2
DIFFICULTY_INCREASE_RATE = .05
MOVE_THRESHOLD = 10  # when moverate counts up to this the snake moves
BLOCK_SPAWN_RATE = 2

TILE_SIZE = (10, 10)
TILE_RECT = pygame.Rect(0, 0, TILE_SIZE[0], TILE_SIZE[1])

SCREENTILES = ((SCREENSIZE[0] / TILE_SIZE[0]) - 1, (SCREENSIZE[1] / TILE_SIZE[1]) - 1)

SNAKE_HEAD_RADIUS = 5
SNAKE_SEGMENT_RADIUS = 4
FOOD_RADIUS = 4

BACKGROUND_COLOR = (255, 255, 255)
SNAKE_HEAD_COLOR = (150, 0, 0)
SNAKE_SEGMENT_COLOR = (255, 182, 193)
FOOD_COLOR = (0, 255, 0)
BLOCK_COLOR = (0, 0, 150)
COLORKEY_COLOR = (255, 255, 0)

SCORE_COLOR = (0, 0, 0)
SCORE_POS = (20, 20)
SCORE_PREFIX = 'Score: '

MOVE_VECTORS = {'left': (-1, 0),
                'right': (1, 0),
                'up': (0, -1),
                'down': (0, 1)
                }
MOVE_VECTORS_PIXELS = {'left': (-TILE_SIZE[0], 0),
                       'right': (TILE_SIZE[0], 0),
                       'up': (0, -TILE_SIZE[1]),
                       'down': (0, TILE_SIZE[1])
                       }

# ~~~
start_button = None
